package com.dcpai.datafactory;

import java.util.List;

/**
 * Created by Administrator on 2016/7/29.
 */
class CatchDataTaskQueue {
    private List<Runnable> mTaskQueue;

    class TaskThread extends Thread {
        private final List<Runnable> workQueue;

        public TaskThread(List<Runnable> workQueue, String name) {
            super(name);
            this.workQueue = workQueue;
        }

        private Runnable getWork() {
            synchronized (workQueue) {
                try {
                    while (workQueue.isEmpty())
                        workQueue.wait();
                    return workQueue.remove(0);
                } catch (InterruptedException ie) {
                    throw new AssertionError(ie);
                }
            }
        }

        @Override
        public void run() {
            for (; ; )
                getWork().run();
        }
    }
}
